﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Esint.Common.Data;
using Esint.JudicialAuction.Model;
using Esint.JudicialAuction.IDAL;
using Esint.Common.Model;
using System.Data.SqlClient;
using Esint.Common;

namespace Esint.JudicialAuction.SqlDAL
{
    /// <summary>
    /// 模块名称： 数据访问层
    /// 作    者：谷明
    /// 生成日期：2020年03月02日
    /// 生成模板: Esint.Template.SqlDAL.SqlDAL_11 版
    ///           适用于工厂模式架构
    /// 修改说明：
    /// </summary>
    public partial class Sys_CodeData  : BaseData, ISys_CodeData
    {
        /// <summary>
        /// 根据flag获得代码列表
        /// </summary>
        /// <param name="flag"></param>
        /// <returns></returns>
        public List<Sys_CodeInfo> GetCodeListByFlag(string flag)
        {
            DataQuery query = new DataQuery();
            query.SQLText = "select * from T_Sys_Code where flag=@flag";
            query.WhereParameters.Add(new WhereParameter("@flag", flag));

            return GetSys_CodeList(query);
        }

        /// <summary>
        /// 根据flag列表查询出对应的代码列表
        /// </summary>
        /// <param name="flagList"></param>
        /// <returns></returns>
        public List<Sys_CodeInfo> GetCodeListByFlagList(List<string> flagList)
        {
            DataQuery query = new DataQuery();
            string strWhere = GetListSqlAndParams(flagList, query.WhereParameters);
            
            query.SQLText = $"select * from T_Sys_Code where flag in {strWhere}";

            return GetSys_CodeList(query);
        }

        public Sys_CodeInfo GetCodeObjectByFlagAndMeaning(string flag, string meaning)
        {
            DataQuery query = new DataQuery();
            query.SQLText = "select top 1 * from T_Sys_Code where flag = @flag and meaning = @meaning";
            query.WhereParameters.Add(new WhereParameter("@flag", flag));
            query.WhereParameters.Add(new WhereParameter("@meaning", meaning));

            return GetModelByQuery(query, CreateSys_CodeInfoByReader);
        }
    }
} 
